/*-------------------------------------------------------------------------*/
/**
  @file		defs.h
  @author	Renaud Wanchoor
  @date	july 2004
  @version	$Revision: 2.5 $
  @brief	Macro definitions

  Defines macros used only by pagrid, some macros may be defined 
  if they are only used in one file
  
*/
/*--------------------------------------------------------------------------*/

/** \brief compute information about a reassignement.
 *
 *  compute deltaF, deltaT, deltaO and dOflag for a reassignment of v 
 *  from pro from to pro to 
 */
#define COMPUTEREFINFO(v,from,to,vwgt,prospeed,procs,procon,npro,ratio,connect,latency,deltaF,deltaT,deltaO,dOflag){	\
  int _i;											\
  deltaF = -vwgt[v]*prospeed[from]-procs[to]*ratio[from][to]+procs[from]*ratio[from][to];	\
  deltaT =  vwgt[v]*prospeed[to]-procs[to]*ratio[to][from]+procs[from]*ratio[to][from];		\
  if(connect[from][to] == procon[to] && procon[from] == 0){					\
    deltaF -= latency[from][to];								\
    deltaT -= latency[to][from];								\
  }												\
  if(connect[from][to] == 0 && connect[to][from] == 0 && procon[from] != 0){			\
    deltaF += latency[from][to];								\
    deltaT += latency[to][from];								\
  }												\
  deltaO = 0;											\
  dOflag = 0;											\
  for(_i=0;_i<npro;_i++){										\
    if(_i == to || _i == from || procs[_i] == 0)							\
      continue;											\
    deltaF -= procs[_i]*ratio[from][_i];								\
    deltaT += procs[_i]*ratio[to][_i];								\
    deltaO += procs[_i]*(ratio[_i][to] - ratio[_i][from]);						\
    if(connect[from][_i] == procon[_i]){								\
      deltaF -= latency[from][_i];								\
      deltaO -= latency[_i][from];								\
    }												\
    if(connect[to][_i] == 0){									\
      deltaT += latency[to][_i];									\
      deltaO += latency[_i][to];									\
    }												\
    dOflag  = 1;										\
  }												\
} 
/** \brief reassign a vertex. The move cannot be undone
 *
 * performs all required update when a reassignment rinfo is done, 
 * the reassignment is inserted into the recent move list 
 */
#define MOVE(ctrl,rinfo){							\
  int moveidx  = (rinfo)->idx;							\
  int moveto   = (rinfo)->to;							\
  int movefrom = (rinfo)->from;							\
  UpdateConnect(ctrl,rinfo);							\
  (ctrl)->g->pro[moveidx] = moveto;						\
  UpdatePHeap(ctrl,rinfo);		       					\
  UpdateHeap(ctrl,rinfo,1);							\
  UpdateProcessorCon((ctrl)->n,(ctrl)->g,moveidx,movefrom,moveto);		\
} 
/** \brief reassign a vertex, the move can be undone.
 *
 * performs all required update when a reassignment rinfo is done, 
 * the reassignment is not inserted into the recent move list 
 */
#define MOVE_NOUNDO(ctrl,rinfo){						\
  int moveidx  = (rinfo)->idx;							\
  int moveto   = (rinfo)->to;							\
  int movefrom = (rinfo)->from;							\
  UpdateConnect(ctrl,rinfo);							\
  (ctrl)->g->pro[moveidx] = moveto;						\
  UpdatePHeap(ctrl,rinfo);		       					\
  UpdateHeap(ctrl,rinfo,0);							\
  UpdateProcessorCon((ctrl)->n,(ctrl)->g,moveidx,movefrom,moveto);		\
}
